﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;

namespace Viking
{
    class Client
    {
        private static IPEndPoint ip;
        private static Socket server;
        public static Boolean sendScore(int score)
        {

            ip = new IPEndPoint(IPAddress.Parse("128.143.69.241"), 9070);
            server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            try
            {
                server.Connect(ip);
            }
            catch (SocketException e)
            {
                Console.WriteLine("Unable to connect to server.");
                return false;
            }


            Console.WriteLine(score);
            server.Send(Encoding.ASCII.GetBytes("sendScore " + score + " \r\n"));
            byte[] data = new byte[1024];
            server.Shutdown(SocketShutdown.Both);
            server.Close();
            return true;
        }
        public static string getScore()
        {
            ip = new IPEndPoint(IPAddress.Parse("128.143.69.241"), 9070);
            server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            try
            {
                server.Connect(ip);
            }
            catch (SocketException e)
            {
                Console.WriteLine("Unable to connect to server.");
                return null;
            }
            server.Send(Encoding.ASCII.GetBytes("getScore\r\n"));
            byte[] data = new byte[1024];
            int receivedDataLength = server.Receive(data);
            string stringData = Encoding.ASCII.GetString(data, 0, receivedDataLength);
            Console.WriteLine(stringData);
            server.Shutdown(SocketShutdown.Both);
            server.Close();
            return stringData;
        }
    }
}
